import java.util.ArrayList;
import java.awt.*;

public class Maze extends Canvas{
	private static final long serialVersionUID = 1L;
	
	public Maze (int map[][]) {
		mapMatrix = new Thing[map.length][map.length];
		monsterList = new ArrayList<Monster>();
		for (int i = 0; i < map.length; i++) {
			for (int j = 0; j < map.length; j++) {
				boolean isEmpty = true; 
				boolean isMonster = true;
				AbstractFactory factory = null;
				switch (map[i][j]) {
		            case 4: 
		            	factory = new SmartStrategyFactory();
		            	isEmpty = false;
		            	break;
		            case 5: 
		            	factory = new RandomStrategyWithEyesFactory();
		            	isEmpty = false;
		            	break;
		            case 6: 
		            	factory = new RandomStrategyFactory();
		            	isEmpty = false;
		            	break;
		            case 7: 
		            	factory = new SurroundStrategyFactory();
		            	isEmpty = false;
		            	break;
		            case 2: 
		            	factory = new CherryFactory();
		            	isEmpty = false;
		            	isMonster = false;
		            	break;
		            case 1: 
		            	factory = new PointFactory();
		            	isEmpty = false;
		            	isMonster = false;
		            	break;
		            case 0:
		            	factory = new WallFactory();
		            	isEmpty = false;
		            	isMonster = false;
		            	break;
				}
				if (!isEmpty) {
					if (isMonster) 
						monsterList.add((Monster)factory.create(i, j));
					else
						mapMatrix[i][j] = factory.create(i, j);
				}
			}
		}
	}
	
	public void drawPackmanAndMonsters() {
		final Graphics g = getGraphics();
		packman.draw(g);
		for (MonsterDraw monster : monsterList) {
			monster.draw(g);
		}
	}
	
	public void movePackmanAndMonsters() {
		packman.move();
		for (MonsterController monster : monsterList) {
			monster.move(mapMatrix, packman.getX(), packman.getY());
		}
	}
	
	public void hidePackmanAndMonsters() {
		packman.hide();
		for (MonsterDraw monster : monsterList) {
			monster.hide();
		}
	}
	
	
	
	private	Packman packman;	
	
	private ArrayList<Monster> monsterList;
	
	private Thing mapMatrix[][];
	
			

}